package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseProductBrand;
import com.sumi.erp.service.IBaseProductBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品厂商Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/erp/brand")
public class BaseProductBrandController extends BaseController
{
    @Autowired
    private IBaseProductBrandService baseProductBrandService;

    /**
     * 查询产品厂商列表
     */
    @PreAuthorize("@ss.hasPermi('erp:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseProductBrand baseProductBrand)
    {
        startPage();
        List<BaseProductBrand> list = baseProductBrandService.selectBaseProductBrandList(baseProductBrand);
        return getDataTable(list);
    }

    /**
     * 导出产品厂商列表
     */
    @PreAuthorize("@ss.hasPermi('erp:brand:export')")
    @Log(title = "产品厂商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseProductBrand baseProductBrand)
    {
        List<BaseProductBrand> list = baseProductBrandService.selectBaseProductBrandList(baseProductBrand);
        ExcelUtil<BaseProductBrand> util = new ExcelUtil<BaseProductBrand>(BaseProductBrand.class);
        util.exportExcel(response, list, "产品厂商数据");
    }

    /**
     * 获取产品厂商详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:brand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseProductBrandService.selectBaseProductBrandById(id));
    }

    /**
     * 新增产品厂商
     */
    @PreAuthorize("@ss.hasPermi('erp:brand:add')")
    @Log(title = "产品厂商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseProductBrand baseProductBrand)
    {
        return toAjax(baseProductBrandService.insertBaseProductBrand(baseProductBrand));
    }

    /**
     * 修改产品厂商
     */
    @PreAuthorize("@ss.hasPermi('erp:brand:edit')")
    @Log(title = "产品厂商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseProductBrand baseProductBrand)
    {
        return toAjax(baseProductBrandService.updateBaseProductBrand(baseProductBrand));
    }

    /**
     * 删除产品厂商
     */
    @PreAuthorize("@ss.hasPermi('erp:brand:remove')")
    @Log(title = "产品厂商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseProductBrandService.deleteBaseProductBrandByIds(ids));
    }
}
